package cn.wolfcode.wms.qo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@Setter
@Getter
public class OrderChartQueryObject extends QueryObject {


    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDate ;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;
    private Long supplierId = -1L;
    private Long brandId = -1L;
    private String groupBy;

    public static final Map<String ,String> groupBys = new LinkedHashMap<>();

    static {
        groupBys.put("e.name","订货人员");
        groupBys.put("p.name","货品名称");
        groupBys.put("s.name","供应商");
        groupBys.put("p.brand_name","品牌");
        groupBys.put("DATE_FORMAT(bill.vdate,\'%Y-%m\')","订货日期(月)");
        groupBys.put("DATE_FORMAT(bill.vdate,\'%Y-%m-%d\')","订货日期(日)");
    }

    private void setEndDate(Date date){
        if(date == null){
            return;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY,23);
        calendar.set(Calendar.MINUTE ,59);
        calendar.set(Calendar.SECOND, 59 );
        this.endDate = calendar.getTime();
    }

}
